#pragma once

#include <algorithm>
#include <array>
#include <type_traits>
#include <tuple>

namespace solar::const_expr
{
    template <typename Key, typename Value, std::size_t Size> struct Map
    {
            std::array<std::pair<Key, Value>, Size> data;

            [[nodiscard]] constexpr auto at(const Key& key) const -> Value
            {

                const auto itr = std::find_if(begin(data), end(data),
                                              [&key](const auto& v) { return v.first == key; });
                if (itr != end(data))
                {
                    return itr->second;
                }
                if constexpr (std::is_constant_evaluated())
                {
                    return {};
                }
                else
                {
                    throw std::range_error("Not Found");
                }
            }

            [[nodiscard]] constexpr auto at2(const Key& key) const -> std::tuple<Value, bool>
            {
                const auto itr = std::find_if(begin(data), end(data),
                                              [&key](const auto& v) { return v.first == key; });
                if (itr != end(data))
                {
                    return {itr->second, true};
                }
                return {{}, false};
            }
    };
} // namespace solar::const_expr
